﻿Imports System.Data.Linq
Imports System.Data.Linq.Mapping
Public Class GlamUp
    Inherits DataContext
    Public Brands As Table(Of Brand)
    Public Images As Table(Of Image)
    Public Categories As Table(Of Category)
    Public Products As Table(Of Product)

    Public Sub New(ByVal conn As String)
        MyBase.New(conn)
    End Sub

End Class

<Table(Name:="brands")> _
Public Class Brand
    <Column(Name:="brand_id", IsPrimaryKey:=True)> _
    Public brandId As String

    <Column(Name:="brand_name")> _
    Public brandName As String
End Class

<Table(Name:="categories")> _
Public Class Category
    <Column(Name:="category_id", IsPrimaryKey:=True)> _
    Public categoryId As String

    <Column(Name:="category_name")> _
    Public categoryName As String

End Class

<Table(Name:="products")> _
Public Class Product
    <Column(Name:="product_id", IsPrimaryKey:=True)> _
    Public productId As String

    '<Column(Name:="category_id")> _
    'Public categoryId As Int32

    '<Column(Name:="brand_id")> _
    'Public brandId As Int32


    <Column(Name:="product_name", Storage:="_productName")> _
    Private _productName As String
    Public Property ProductName() As String
        Get
            Return Me._productName
        End Get
        Set(ByVal value As String)
            Me._productName = value
        End Set
    End Property

    Public Property tt() As String
        Get
            Return "q"
        End Get
        Set(ByVal value As String)
            value = "q"
        End Set
    End Property

    <Column(Name:="sku")> _
    Public sku As String


    <Column(Name:="brand_id")> _
    Public brandId As String

    <Column(Name:="category_id")> _
    Public categoryId As String

    Private _brand As EntityRef(Of Brand)
    <Association(Name:="FK_products_categories1", Storage:="_brand", ThisKey:="brandId", IsForeignKey:=True)> _
    Public Property Brand() As Brand
        Get
            Return (Me._brand.Entity)
        End Get
        Set(ByVal value As Brand)
            Dim previousValue As Brand = Me._brand.Entity
            If ((Object.Equals(previousValue, value) = False) _
               OrElse (Me._brand.HasLoadedOrAssignedValue = False)) Then
                Me._brand.Entity = Nothing

            End If
            Me._brand.Entity = value
            Me.brandId = value.brandId

        End Set
    End Property

    Private _category As EntityRef(Of Category)
    <Association(Name:="FK_products_categories", Storage:="_category", ThisKey:="categoryId", IsForeignKey:=True)> _
    Public Property Category() As Category
        Get
            Return (Me._category.Entity)
        End Get
        Set(ByVal value As Category)
            Dim previousValue As Category = Me._category.Entity
            If ((Object.Equals(previousValue, value) = False) _
               OrElse (Me._category.HasLoadedOrAssignedValue = False)) Then
                Me._category.Entity = Nothing
            End If
            Me._category.Entity = value
            Me.categoryId = value.categoryId

        End Set
    End Property

    Private _images As EntitySet(Of Image)
    <Association(Name:="FK_images_products", Storage:="_images", OtherKey:="productId")> _
    Public Property Images() As EntitySet(Of Image)
        Get
            Return Me._images
        End Get
        Set(ByVal value As EntitySet(Of Image))
            Me._images.Assign(value)
        End Set
    End Property

    Public Sub New()
        Me._images = New EntitySet(Of Image)
    End Sub

End Class

<Table(Name:="images")> _
Public Class Image
    <Column(Name:="image_id", IsPrimaryKey:=True)> _
    Public imageId As String

    <Column(Name:="product_id")> _
    Public productId As string

    <Column(Name:="path")> _
    Public path As String

    <Column(Name:="is_main")> _
    Public isMain As Boolean

End Class
